﻿@model OJS.Web.ViewModels.Search.SearchResultGroupViewModel
@using Resource = Resources.Search.Views.SearchResults;

@{
    ViewBag.Title = string.Format(Resource.Title, Model.SearchTerm);
}


@if (Model.IsSearchTermValid)
{
    <h1>@ViewBag.Title</h1>
    
    foreach (var resultGroup in Model.SearchResults)
    {
        if (resultGroup.Key == SearchResultType.Problem && resultGroup.Value.Any())
        {
            int problemCounter = 0;
            <div class="row">
                <h4 class="col-lg-12">@Resource.Problems: </h4>
                <hr />
                @foreach (var problemResult in resultGroup.Value)
                {
                    <div class="col-lg-3 well">
                        <div><span class="text-white">@problemResult.Name</span> @Resource.From_contest </div>
                        <a href="@ContestsHelper.GetUrl(problemResult.ParentId.Value, problemResult.ParentName)">
                            @problemResult.ParentName
                        </a>
                    </div>
                    {
                        problemCounter++;
                        if (problemCounter % 4 == 0)
                        {
                            @:</div><div class="row">
                        }
                    }
                }
            </div>
        }

        if (resultGroup.Key == SearchResultType.Contest && resultGroup.Value.Any())
        {
            int contestCounter = 0;
            <div class="row">
                <h4 class="col-lg-12">@Resource.Contests: </h4>
                <hr />
                @foreach (var contestResult in resultGroup.Value)
                {
                    <div class="col-lg-3 well">
                        <a href="@ContestsHelper.GetUrl(contestResult.Id, contestResult.Name)">
                            @contestResult.Name
                        </a>
                    </div>
                    {
                        contestCounter++;
                        if (contestCounter % 4 == 0)
                        {
                            @:</div><div class="row">
                        }
                    }
                }
            </div>
        }

        if (resultGroup.Key == SearchResultType.User && resultGroup.Value.Any())
        {
            int userCounter = 0;
            <div class="row">
                <h4 class="col-lg-12">@Resource.Users: </h4>
                <hr />
                @foreach (var userResult in resultGroup.Value)
                {
                    <div class="col-lg-3 well">
                        @Html.ActionLink(userResult.Name, GlobalConstants.Index, new { controller = "Profile", area = "Users", id = userResult.Name })
                    </div>
                    {
                        userCounter++;
                        if (userCounter % 4 == 0)
                        {
                            @:</div><div class="row">
                        }
                    }
                }
            </div>
        }
    }
} else {
    <p class="lead text-warning">@string.Format(Resource.Search_term_too_short, Model.MinimumSearchTermLength)</p>
}